package com.example.shop.controller.backstage;

import com.alibaba.fastjson.JSON;
import com.example.shop.model.CommodityType;
import com.example.shop.service.CommodityTypeService;
import com.example.shop.utils.PageBean;
import com.example.shop.utils.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/backstage")
public class BackCommodityTypeController {
    @Resource
    private CommodityTypeService commodityTypeService;

    @RequestMapping("/getCommodityType")
    public String getCommodityType(@RequestParam(defaultValue = "1") Integer pageNo, @RequestParam(defaultValue = "5") Integer pageSize, @RequestParam(defaultValue = "") String search) {
        PageBean<CommodityType> users = commodityTypeService.getCommodityType(pageNo, pageSize, search);
        Result<PageBean<CommodityType>> res = new Result<>();
        res.setCode("0");
        res.setData(users);
        return JSON.toJSONString(res);
    }
}
